<?php

class Model_Useradmin extends Model_Database
{
	var $table = 'useradmin';
	
	public function check($user, $password){
		$password = $this->generate_password($user, $password);
		$sql = "select uid from {$this->table} where status=0 and user='{$user}' and password='{$password}'";
		$re = $this->_db->query(Database::SELECT, $sql);
		return $re->as_array();
	}
	
	public function update($data, $uid){
		$val_arr = array();
		foreach ($data as $key => $record){
			$val_arr[] = "{$key}='{$record}'";
		}
		$val_str = implode(',', $val_arr);
		$sql = "update {$this->table} set {$val_str} where uid={$uid}";
		return $this->_db->query(Database::UPDATE, $sql);
	}
	
	private function generate_password($user, $password){
		return md5(md5($user . $password) . $password);
	}
}